package handler

import (
	"encoding/json"
	"fmt"
	"github.com/xiaoqinghong/super_daemon/core"
	"net/http"
)

func HandlePost(w http.ResponseWriter, r *http.Request) {
	if r.Method != http.MethodPost {
		w.Write([]byte("error http method"))
		return
	}
	cmd := r.FormValue("cmd")
	w.Write([]byte(fmt.Sprintf("%s success", cmd)))
}

func HandleGet(w http.ResponseWriter, r *http.Request) {
	if r.Method != http.MethodGet {
		w.Write([]byte("error http method"))
		return
	}
	//query := r.URL.Query()
	//cmd := query.Get("cmd")
	list := core.Instance().List()
	bytes, _ := json.Marshal(list)
	w.Write(bytes)
}
